package net.hn.hnms.biz.emgcy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.hn.hnms.biz.emgcy.domain.EmgcyLocatePo;
import net.hn.hnms.biz.emgcy.domain.dto.EmgcyLocateDto;
import net.hn.hnms.biz.emgcy.domain.vo.EmgcyLocateVo;
import net.hn.hnms.biz.emgcy.mapper.EmgcyLocateMapper;
import net.hn.hnms.biz.emgcy.service.EmgcyLocateService;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: baijiajun
 * @Date: 2022/9/13
 */
@Service
public class EmgcyLocateServiceImpl extends ServiceImpl<EmgcyLocateMapper, EmgcyLocatePo> implements EmgcyLocateService {
    @Autowired
    private EmgcyLocateMapper emgcyLocateMapper;
    @Override
    public ResponsePage<EmgcyLocateVo> pageList(PageQuery pageQuery, EmgcyLocateDto emgcyLocateDto) {
        pageQuery.setPageNum(pageQuery.getPageNum() >= 1 ? (pageQuery.getPageNum() - 1) * pageQuery.getPageSize():0);
        List<EmgcyLocateVo> list =  emgcyLocateMapper.pageList(pageQuery.getPageSize(), pageQuery.getPageNum(), emgcyLocateDto);
        if(list.isEmpty()){
            return new ResponsePage<>(new ArrayList(),0);
        }
        return new ResponsePage<>(list,list.get(0).getTotal());
    }

    @Override
    public Boolean update(EmgcyLocatePo emgcyLocatePo) {
        int update = emgcyLocateMapper.updateById(emgcyLocatePo);
        if(update>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean delete(Long id) {
        int delete = emgcyLocateMapper.deleteById(id);
        if(delete>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean add(EmgcyLocatePo emgcyLocatePo) {
        int insert = emgcyLocateMapper.insert(emgcyLocatePo);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public EmgcyLocatePo getOne(String eventType) {
        return emgcyLocateMapper.getOne(eventType);
    }
}
